package daily.play1;

import java.io.*;
import java.nio.charset.Charset;
import java.util.Arrays;

//public class demo13 {
//    public static void main(String[] args) throws IOException {
//        String str = "刘志鹏";
//        byte [] arr = str.getBytes();
//        System.out.println(Arrays.toString(arr));
//        byte [] arr2 = str.getBytes("GBK");
//        System.out.println(Arrays.toString(arr2));
//        String str3 = new String(arr);
//        System.out.println(str3);
//        String str4 = new String(arr,"GBK");
//        System.out.println(str4);
//        FileReader fid = new FileReader("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt");
//        int n;
//        while((n=fid.read())!=-1){
//            System.out.print((char) n);
//        }
//        fid.close();
//        FileReader fid = new FileReader("D:\\\\java-code\\\\daily-java\\\\src\\\\daily\\\\play1\\\\test.txt");
//        char [] arr = new char[2];
//        int n;
//        while((n=fid.read(arr))!=-1){
//            System.out.println(new String(arr));
//        }
//    }
//}

//public class demo13{
//    public static void main(String[] args) throws IOException {
//        FileWriter fww = new FileWriter("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt");
//        for (int i = 0; i < 512; i++) {
//            fww.write(97);
//        }
//        System.out.println("----------");
//    }
//}


//文件夹的拷贝
//public class demo13{
//    public static void main(String[] args) throws IOException {
//        File fis = new File("D:\\html");
//        File fos = new File("D:\\copy");
//        copy(fis,fos);
//    }
//    public static void copy(File fis,final File fos) throws IOException {
//        File[] files = fis.listFiles();
//        if(files==null){
//            return ;
//        }
//        for(File f:files){
//            //如果现在是文件
//            if(f.isFile()){
//                FileInputStream fis2 = new FileInputStream(f);
//                FileOutputStream fos2 = new FileOutputStream(new File(fos,f.getName()));
//                byte[] buf = new byte[1024];
//                int len = 0;
//                while((len = fis2.read(buf))!=-1){
//                    fos2.write(buf,0,len);
//                }
//            }
//            else{
//                copy(f,new File(fos,f.getName()));
//            }
//        }
//    }
//}

//缓冲流拷贝文件
//public class demo13 {
//    public static void main(String[] args) throws IOException {
//        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt"));
//        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("D:\\java-code\\daily-java\\src\\daily\\play1\\copy.txt"));
//        int n;
//        long startTime = System.currentTimeMillis();
//        while ((n = bis.read())!=-1){
//            bos.write(n);
//        }
//        long endTime = System.currentTimeMillis();
//        System.out.println(endTime-startTime);
//        bos.close();
//        bis.close();
//        FileInputStream fis = new FileInputStream("D:\\\\java-code\\\\daily-java\\\\src\\\\daily\\\\play1\\\\test.txt");
//        FileOutputStream  fos = new FileOutputStream("D:\\\\java-code\\\\daily-java\\\\src\\\\daily\\\\play1\\\\copy.txt");
//        int n;
//        long startTime  = System.currentTimeMillis();
//        while((n = fis.read())!=-1){
//            fos.write(n);
//        }
//        long endTime = System.currentTimeMillis();
//        System.out.println(endTime - startTime);
//        fos.close();
//        fis.close();
//        BufferedInputStream bif = new BufferedInputStream(new FileInputStream("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt"));
//        BufferedOutputStream bof = new BufferedOutputStream(new FileOutputStream("D:\\java-code\\daily-java\\src\\daily\\play1\\copy.txt"));
//        byte[] buf = new byte[1024];
//        long start = System.currentTimeMillis();
//        int len;
//        while ((len = bif.read(buf)) != -1) {
//            bof.write(buf, 0, len);
//        }
//        long end = System.currentTimeMillis();
//        System.out.println(end - start);
//        bof.close();
//        bif.close();
//        //1.readLine()
//        BufferedReader br = new BufferedReader(new FileReader("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt"));
//       String str;
//       while((str = br.readLine())!=null){
//           System.out.println(str);
//       }
        //2.newline()
//        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\java-code\\daily-java\\src\\daily\\play1\\copy.txt"));
//        bw.write("他的梦想是成为一名画家，用画笔记录下这个美丽的地方。");
//        bw.newLine();
//        bw.close();
//    }
//}

//4中拷贝的方式
//public class demo13{
//    public static void main(String[] args) throws IOException {
//        long startTime = System.currentTimeMillis();
//        FileInputStream fis = new FileInputStream("E:\\video\\眼泪女王(高画质).mp4");
//        FileOutputStream fos = new FileOutputStream("src\\copy_mp4_tearqueen.mp4");
//        int n;
//        while((n = fis.read())!=-1){
//            fos.write(n);
//        }
//        long endTime = System.currentTimeMillis();
//        System.out.println(endTime-startTime);
//        fos.close();
//        fis.close();

//        long startTime = System.currentTimeMillis();
//        FileInputStream fis = new FileInputStream("E:\\\\video\\\\眼泪女王(高画质).mp4");
//        FileOutputStream fos = new FileOutputStream("src\\\\copy_mp4_tearqueen.mp4");
//        byte[] buf = new byte[1024];
//        int len;
//        while((len = fis.read(buf))!=-1){
//            fos.write(buf,0,len);
//        }
//        long endTime = System.currentTimeMillis();
//        System.out.println((endTime-startTime)/1000.0+"秒");
//        fos.close();
//        fis.close();

//        long startTime = System.currentTimeMillis();
//        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("E:\\\\video\\\\眼泪女王(高画质).mp4"));
//        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("src\\\\\\\\copy_mp4_tearqueen.mp4"));
//        int n;
//        while((n = bis.read())!=-1){
//            bos.write(n);
//        }
//        long endTime = System.currentTimeMillis();
//        System.out.println((endTime-startTime)/1000.0+"秒");
//        bos.close();
//        bis.close();

//        long startTime = System.currentTimeMillis();
//        BufferedInputStream fis = new BufferedInputStream(new FileInputStream("E:\\video\\眼泪女王(高画质).mp4"));
//        BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream("src\\copy_mp4_tearqueen.mp4"));
//        byte[] buf = new byte[1024];
//        int len=0;
//        while((len = fis.read(buf))!=-1){
//            fos.write(buf,0,len);
//        }
//        long endTime = System.currentTimeMillis();
//        System.out.println((endTime-startTime)/1000.0+"秒");
//        fos.close();
//        fis.close();
//        int a=2147483647+2;
//        System.out.println(a);
//    }
//}

//IO流：随用随创建
        //不用就关闭
//public class demo13{
//    public static void main(String [] arga) throws IOException {
//        BufferedReader br = new BufferedReader(new FileReader("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt"));
//        int count = Integer.parseInt(br.readLine());
//        br.close();
//        count++;
//        if(count<=3){
//            System.out.println("欢迎使用，这是你的第"+count+"次使用");
//        }else if(count>=4){
//            System.out.println("很抱歉，免费使用次数已经使用完毕！这是你的第"+count+"次使用");
//        }
//        BufferedWriter bw = new BufferedWriter(new FileWriter("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt"));
//        bw.write(count+"");
//        bw.close();
//        FileOutputStream fos = new FileOutputStream();
//        FileReader fr = new FileReader("D:\\java-code\\daily-java\\src\\daily\\play1\\test.txt", Charset.forName("UTF-8"));
//        int n;
//      while ((n = fr.read())!=-1){
//          System.out.print((char) n);
//      }
//      fr.close();
//        FileReader fr = new FileReader("D:\\\\java-code\\\\daily-java\\\\src\\\\daily\\\\play1\\\\test.txt",Charset.forName("GBK"));
//        FileWriter fw = new FileWriter("src\\daily\\play1\\copy.txt",Charset.forName("UTF-8"));
//        int n ;
//        while((n = fr.read())!=-1){
//            fw.write(n);
//        }
//        fw.close();
//        fr.close();
//        FileInputStream fis = new FileInputStream("D:\\java-code\\daily-java\\src\\daily\\play1\\copy.txt");
//        InputStreamReader isr = new InputStreamReader(fis);
//        BufferedReader br = new BufferedReader(isr);
//        String str ;
//        while((str = br.readLine())!=null){
//            System.out.println(str);
//        }
//        br.close();
//    }
//}